import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/login/index.vue'
import DefaultLayout from '@/layouts/default/index.vue'
import Home from '@/views/home/index.vue'
import Category from '@/views/category/index.vue'
import SubCategory from '@/views/sub-category/index.vue'
import Detail from '@/views/detail/index.vue'
import CartList from '@/views/cartlist/index.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'default',
      component: DefaultLayout,
      children: [
        {
          path: '',
          name: 'home',
          component: Home,
        },
        {
          path: 'category/:id',
          name: 'category',
          component: Category,
        },
        {
          path: 'category/sub/:id',
          name: 'subCategory',
          component: SubCategory,
        },
        {
          path: 'detail/:id',
          name: 'detail',
          component: Detail,
        },
        {
          path: 'cartlist',
          name: 'cartList',
          component: CartList,
        },
      ],
    },
    {
      path: '/login',
      name: 'login',
      component: Login,
    },
  ],
  //路由行为
  scrollBehavior() {
    return {
      top: 0,
    }
  },
})

export default router
